package cn.xm.basic.aop;

import cn.xm.basic.anno.LogAnno;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Component
@Aspect
public class LogAop {

    @Pointcut("@annotation(cn.xm.basic.anno.LogAnno)")
    public void pointCut() {}

    @Around("pointCut()")
    public Object around(ProceedingJoinPoint pjp) {
        MethodSignature signature = (MethodSignature)pjp.getSignature();
        // 获取所有方法
        Method method = signature.getMethod();
        // 获取注释
        LogAnno annotation = method.getAnnotation(LogAnno.class);
        // 获取注释的字段
        String method2 = annotation.method();
        String methodDes = annotation.methodDes();

        Object proceed = null;
        try {
            proceed = pjp.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return proceed;
    }
}
